package com.wmm.servlet.student;

import com.wmm.bean.PageBean;
import com.wmm.bean.Student;
import com.wmm.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "DeleteStudentServlet" ,urlPatterns = "/deleteStudent")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String studentno = request.getParameter("studentno");
        String classNo = request.getParameter("classNo");
        StudentService studentService = new StudentService();
        boolean flag = studentService.deleteStudentServer(studentno,classNo);
        if(flag) {
            System.out.println("删除成功");
            HttpSession session = request.getSession();
            StudentService service = new StudentService();
            String studentno1 = (String) session.getAttribute("bystudentno");
            String name = (String) session.getAttribute("byname");
            PageBean<Student> queryList = service.findQueryStudentByPage("1","5",studentno1,name);

            session.setAttribute("queryList",queryList);
            response.sendRedirect("show.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
